﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace RealEstateCenter
{
    public partial class ShowImage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
                string connectionString;
                SqlConnection sqlconnect;
                connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|RealEstateCenter.mdf;Integrated Security=True;User Instance=True";
                sqlconnect = new SqlConnection(connectionString);
                SqlCommand cmd = new SqlCommand("SELECT estate_image from Estate where estate_id=" + Request.QueryString["id"], sqlconnect);
                SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter();
                mySqlDataAdapter.SelectCommand = cmd;
                DataTable resimdata = new DataTable();
                sqlconnect.Open();
                mySqlDataAdapter.Fill(resimdata);
                SqlDataReader dr = cmd.ExecuteReader();
                byte[] resim = null;
                if (dr.Read())
                {
                    resim = (byte[])resimdata.Rows[0]["estate_image"];
                }
                sqlconnect.Close();
                if (resim != null)
                {
                    Response.ContentType = "image/jpeg";
                    Response.BinaryWrite(resim);
                }
        }
    }
}